#include <algorithm>
#include <cstdio>

typedef long long ll;
const int N = 1e6 + 5;
int n, k, q[N], l, r;
ll sum[N], f[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("D.in", "r", stdin);
  freopen("D.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &sum[i]);
    sum[i] += sum[i - 1];
  }
  q[r = l = 1] = 0;
  ll ans = 0;
  for (int i = k; i <= n; ++i) {
    f[i] = f[q[l]] + sum[i] - sum[q[l]];
    f[i] = std::max(f[i], f[i - 1]);
    ans = std::max(ans, f[i]);
    while (l <= r && f[i - k + 1] - sum[i - k + 1] > f[q[r]] - sum[q[r]]) --r;
    q[++r] = i - k + 1;
  }
  printf("%lld", ans);
  return 0;
}